﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Controls.Primitives;
using Techstar.Progress;
using Techstar.Dialog;

namespace SmartMD.Manager.Patient
{
    /// <summary>
    /// Interaction logic for PatientManagerWindow.xaml
    /// </summary>
    public partial class PatientManagerWindow : BaseWindow
    {
        private UIElement _queryInfo;
        private UIElement _storeInfo;
        private UIElement _examItemInfo;
        private UIElement _clinicTeatment;
        private string _currentPanelName;

        public PatientManagerWindow()
        {
            InitializeComponent();
            OpenView("患者查询");
        }

        public static string ModuleName 
        {
            get { return "患者资料"; } 
        }

        private void btnOpenView_Click(object sender, RoutedEventArgs e)
        {
            var button = (ToggleButton)sender;

            OpenView(button.Tag.ToString());            
        }
        private void OpenView(string name)
        {
            var progressThread = new ProgressThread(250);
            progressThread.Start("开始打开", "正在打开......");
            try
            {
                progressThread.Step = "正在打开......(" + name + ")";
                Load(name);
            }
            catch (Exception ex)
            {
                TaskDialogEx.Warning("提示信息", ex.Message);
            }
            finally
            {
                progressThread.End();
            }
        }

        protected override void OnWindowActivated()
        {/*
           switch (_currentPanelName)
            {
                case "患者资料查询":
                    (_queryInfo as QueryInfoPanel).OnWindowActivated();
                    break;
                case "患者信息录入":
                    (_storeInfo as StoreInfoPanel).OnWindowActivated();
                    break;
                case "检验检查录入":
                    (_examItemInfo as ExamItemInfoStorePanel).OnWindowActivated();
                    break;
                case "临床治疗录入":
                    (_examItemInfo as ExamItemInfoStorePanel).OnWindowActivated();
                    break;
                default:
                    break;
            }
            */
        }

        public override void Load(object param)
        {
            if (param == null) return;

            foreach (ToggleButton btn in panelButtons.Children)
            {
                btn.IsChecked = btn.Tag.Equals(param);
            }

            var sParam = param.ToString();
            _currentPanelName = sParam;
            this.Title = "患者管理 - " + sParam;
            this.gridContent.Children.Clear();
            switch (sParam)
            {
                case "患者查询":
                    this.gridContent.Children.Add(GetQueryInfoPanel());
                    (_queryInfo as QueryInfoPanel).OnWindowActivated();
                    break;
                case "患者信息":
                    this.gridContent.Children.Add(GetStoreInfoPanel());
                    (_storeInfo as StoreInfoPanel).OnWindowActivated();
                    break;
                case "检验检查":
                    this.gridContent.Children.Add(GetStoreExamItemInfoPanel());
                    (_examItemInfo as ExamItemInfoStorePanel).OnWindowActivated();
                    break;
                case "随访记录": //临床治疗
                    this.gridContent.Children.Add(GetClinicalTreatmentPanel());
                    (_clinicTeatment as ClinicalTreatmentPanel).OnWindowActivated();
                    break;
                
            }
        }

        public UIElement GetQueryInfoPanel()
        {
            return _queryInfo ?? (_queryInfo = new QueryInfoPanel());
        }
        public UIElement GetStoreInfoPanel()
        {
            return _storeInfo ?? (_storeInfo = new StoreInfoPanel());
        }
        public UIElement GetStoreExamItemInfoPanel()
        {
            return _examItemInfo ?? (_examItemInfo = new ExamItemInfoStorePanel());
        }
        public UIElement GetClinicalTreatmentPanel()
        {
            return _clinicTeatment ?? (_clinicTeatment = new ClinicalTreatmentPanel());
        }

        private void btnQuery_Click(object sender, RoutedEventArgs e)
        {
            PatientInfoQueryDialog dlg = new PatientInfoQueryDialog();
            dlg.ShowDialog();
        }
    }
}
